function isNotEmptyObj(obj) {
 for (var key in obj) {
   return false;
 }
 return true;
}
function isNotEmptyArr(arr) {
 return arr.constructor === Array && arr.length === 0 ? false : true;
}
function checkPhone(checkphone) {
 var phone = checkphone.replace(/\s/g, '');
 var reg = /^1[3-9][0-9]{9}$/;
 if (phone === '' || phone === null) {
   return false;
 } else if (!reg.test(phone)) {
   return false;
 } else {
   return true;
 }
}
// 去除字符串内所有的空格
const strEmptyRemove = (str) => {
 str = str.replace(/\s*/g, "");
 return str
}
//数组去重
const uniq = (array) => {
 var temp = []
 for(var i = 0; i < array.length; i++ ) {
   if(temp.indexOf(array[i]) == -1) {
     temp.push(array[i])
   }
 }
 return temp
}
var showLoading = function(val) {
 if (val) {
   val = val;
 } else {
   val = '加载中...';
 }
 wx.showLoading({ content: val });
};
var hideLoading = function() {
 setTimeout(function() {
   wx.hideLoading();
 }, 100);
};
/*toast*/
var showToast = function(res, time, fn) {
 var duration = time || 3000
 wx.showToast({
   title: res, //文字内容
   icon:"none",
   duration: duration, //显示时长
   complete: function() { //调用结束
     if (typeof fn == 'function') {
       var b = setTimeout(() => {
         fn()
         clearTimeout(b)
       }, duration)
     }
   }
 });
}
/*提示框*/
var alert = function(content, fn) {
 wx.alert({
   title: '提示',
   content: content,
   buttonText: '我知道了',
   success: () => {
     if (typeof fn == 'function') {
       fn()
     }
   },
 });
}
var hideMiddle = function(phone) {
 if (checkPhone(phone)) {
   return phone.substring(0, 3) + '****' + phone.substring(7, 11);
 } else {
   return phone;
 }
};
var parseQuery = function(query) {
 var reg = /([^=&\s]+)[=\s]*([^&\s]*)/g;
 var obj = {};
 while (reg.exec(query)) {
   obj[RegExp.$1] = RegExp.$2;
 }
 return obj;
};
var getStorageSync = function(key) {
 let res = wx.getStorageSync({ key: key })
 return res ? res.data : "";
}
var setStorageSync = function(key, data) {
 wx.setStorageSync({
   key: key,
   data: data
 });
}
var removeStorageSync = function(key) {
 wx.removeStorageSync({ key: key });
}
module.exports = {
 strEmptyRemove:strEmptyRemove,
 isNotEmptyObj: isNotEmptyObj,
 isNotEmptyArr: isNotEmptyArr,
 uniq: uniq,
 checkPhone: checkPhone,
 showLoading: showLoading,
 hideLoading: hideLoading,
 showToast: showToast,
 alert: alert,
 hideMiddle: hideMiddle,
 parseQuery: parseQuery,
 getStorageSync: getStorageSync,
 setStorageSync: setStorageSync,
 removeStorageSync: removeStorageSync
}